package com.ibiz.mobapp.controller;

import lombok.Data;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ibiz.ibizutil.domain.ActionResult;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ibiz.ibizutil.errors.BadRequestAlertException;
import org.springframework.validation.annotation.Validated;
import org.springframework.http.ResponseEntity;
import com.fasterxml.jackson.databind.JsonNode;
import com.ibiz.ibizutil.errors.BadRequestAlertException;
import java.io.InputStream;
import com.fasterxml.jackson.databind.ObjectMapper;

@RestController
@RequestMapping("/mobapp/app/mobapp")
public class MobAppController{

	@Data
	static protected class AppData{
		private String remotetag = null;
		private ObjectNode localdata = null;
	}
	
	@RequestMapping("getappdata")
    public ResponseEntity<AppData> getAppData(@Validated HttpServletRequest request){
    		AppData appData = new AppData();
    		fillAppData(appData);
    		return ResponseEntity.ok().body(appData);
    }
    
    protected void fillAppData(@Validated AppData appData){
    
    }


    /**
    * 获取实体模型数据
    * @param filePath 模型文件路径
    * @return
    */
    public ResponseEntity<JsonNode> getDEModel(String filePath){
        JsonNode jsonNode;
        try{
			InputStream in = this.getClass().getResourceAsStream(filePath);
			jsonNode = new ObjectMapper().readTree(in);
        }
        catch(Exception ex){
        	throw new BadRequestAlertException("操作发生错误","","");
        }
        	return ResponseEntity.ok().body(jsonNode);
        }
}